import { customRef } from "vue";

export default function (tmpCode,delay) {
  let timer;
  let code = customRef((track, trigger) => {
    return {
      get() {
        track();
        return tmpCode;
      },
      set(value) {
        clearTimeout(timer);
        timer = setTimeout(() => {
          tmpCode = value;
          trigger();
        }, delay);
      },
    };
  });
  return code;
}
